package com.qingshu.common.util.map;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
/**
 * 描述
 *
 * @author Huzz
 * @create 2022-02-15 09:42
 */
@SuppressWarnings("all")
public class MapUtil {

    public static Map toMap(Bundle bundle) {
        Enumeration enumeration = bundle.getKeys();
        Map map = new HashMap();

        while (enumeration.hasMoreElements()) {
            String key = (String) enumeration.nextElement();
            Object value = bundle.handleGetObject(key);
            map.put(key, value);
        }

        return map;
    }

    /**
     * 得到一个去掉值为空的键值对的map
     * @param bundle
     * @return
     */
    public static Map toNotEmptyValueMap(Bundle bundle) {
        Enumeration enumeration = bundle.getNotEmptyKeys();
        Map map = getMap(bundle, enumeration);

        return map;
    }

    private static Map getMap(Bundle bundle, Enumeration enumeration) {
        Map map = new HashMap();

        while (enumeration.hasMoreElements()) {
            String key = (String) enumeration.nextElement();
            Object value = bundle.handleGetObject(key);
            map.put(key, value);
        }
        return map;
    }
}
